<!--
 * @Descripttion: 试题分类信息
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2021-05-12 17:19:28
 * @LastEditTime: 2021-05-20 22:30:38
 * @FilePath: \cscec-pms-admin\src\views\partyMasses\partyStudyInfo\questionsClassifyInfo\index.vue
-->
<template>
  <!-- 试题分类信息 -->
  <base-breadcrumb class="flexMemberInfo-container">
    <!-- 搜索 -->
    <searchData
      :search-data="searchOption"
      @search="search"
    />
    <!-- 搜索 -->
    <!-- 试题分类信息列表 -->
    <a-card>
      <!-- 表格操作 -->
      <div class="table-operator">
        <!-- <title-name :title="$route.meta.title + '列表'" /> -->
        <a-button
          v-btnPermission="'pa_001_add_01'"
          type="primary"
          icon="plus"
          @click="handleAdd"
        >
          新增
        </a-button>
      </div>
      <!-- 表格操作 -->
      <!-- 表格统计 -->
      <div class="pub-table-select-count">
        <a-icon
          type="info-circle"
          theme="twoTone"
        />
        <span style="margin-right: 12px">
          共计：<span class="totalNum">{{ total || 0 }} </span>个
        </span>
      </div>
      <!-- 表格统计 -->
      <!-- 表格 -->
      <list-table
        ref="table"
        size="default"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :isScrollX="false"
        :alert="true"
        show-size-changer
        show-quick-jumper
      >
        <span
          slot="operator"
          slot-scope="text, record"
        >
          <MoreButton>
            <a
              v-btnPermission="'pa_001_edi_02'"
              @click="handleEdit(record)"
            >编辑</a>
            <a
              v-btnPermission="'pa_001_del_03'"
              @click="handleDelete(record)"
            >删除</a>
          </MoreButton>
        </span>
      </list-table>
      <!-- 表格 -->
    </a-card>
    <!-- 试题分类信息列表 -->
    <!-- 操作模态框 -->
    <operate-form
      :visible.sync="operateVisible"
      :data="operateData"
      @refresh="handleRefresh"
    />
    <!-- 操作模态框 -->
  </base-breadcrumb>
  <!-- 试题分类信息 -->
</template>
<script>
import { STable } from '@/components'
import OperateForm from './components/OperateForm'
import { getPageExamType, deleteByPrimaryKey } from '@/api/partyMasses/partyStudyInfo/questionsClassifyInfo'
export default {
  name:'a'+ Date.now(),
  // name: 'QuestionsClassifyInfo',
  components: {
    STable,
    OperateForm
  },
  data() {
    return {
      // 搜索组件配置
      searchOption: [
        {
          name: '试题分类',
          type: 'input',
          value: 'examTypeName'
        },
        {
          name: '状态',
          value: 'examTypeState',
          type: 'select',
          data: [
            {
              value: 0,
              label: '不可用'
            },
            {
              value: 1,
              label: '可用'
            }
          ]
        }
      ],
      // 表头
      columns: [
        {
          title: '序号',
          width: '80px',
          align: 'center',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return index + 1
          }
        },
        {
          title: '试题分类',
          dataIndex: 'name',
          key: 'name',
          align: 'center'
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          key: 'createTime',
          align: 'center'
        },
        {
          title: '状态',
          dataIndex: 'stateName',
          key: 'stateName',
          align: 'center'
        },
        {
          title: '操作',
          dataIndex: 'operator',
          width: '170px',
          scopedSlots: { customRender: 'operator' }
        }
      ],
      // 查询参数
      searchData: {},
      // 表格共计
      total: 0,
      // 操作编辑模态框显示
      operateVisible: false,
      // 操作模态框数据
      operateData: {
        type: '',
        record: {}
      }
    }
  },
  methods: {
    /**
     * @description: 搜索
     * @param {Object} value 搜索数据
     * @return {Void}
     */
    search(value) {
      this.searchData = value || {}
      this.$refs.table.refresh(true)
    },
    /**
     * @description: 表格数据加载方法
     * @param {Object} parameter 分页信息
     * @return {Promise} 接口Promise
     */
    async loadData(parameter) {
      try {
        const params = Object.assign({}, parameter, { query: this.searchData })
        const { data, currentPage, totalSize,code} = await getPageExamType(params)
        this.total = totalSize
        return Promise.resolve({
          data,
          code,
          currentPage,
          totalSize
        })
      } catch (error) {
        console.log(error)
        return Promise.reject(error)
      }
    },
    /**
     * @description: 新增
     * @param {Void}
     * @return {Void}
     */
    handleAdd() {
      this.operateVisible = true
      this.operateData = {
        type: 'add',
        record: {}
      }
    },
    /**
     * @description: 编辑
     * @param {Object} record 当前行数据
     * @return {Void}
     */
    handleEdit(record) {
      this.operateVisible = true
      this.operateData = {
        type: 'edit',
        record
      }
    },
    /**
     * @description: 删除
     * @param {Object} record 当前行数据
     * @return {Void}
     */
    handleDelete(record) {
      this.$confirm({
        title: '温馨提示',
        content: '确定是否删除数据？',
        okText: '确认',
        okType: 'danger',
        cancelText: '取消',
        onOk: () => {
          deleteByPrimaryKey({ id: record.id })
            .then(({ code, msg }) => {
              if (code === this.SUCCESS_CODE) {
                this.$message.success('删除成功！')
                this.$refs.table.refresh(true)
              } else {
                this.$message.error(msg)
              }
            })
            .catch((error) => {
              console.log(error)
              this.$message.error('删除失败！')
            })
        }
      })
    },
    /**
     * @description: 刷新列表
     * @param {Void}
     * @return {Void}
     */
    handleRefresh() {
      this.search()
    }
  }
}
</script>
<style lang="less" scoped>
</style>

